﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using DTO;
using BUS;

namespace EC21_EDiamond
{
    public partial class QuanLySanPham : System.Web.UI.Page
    {
        
        protected void Page_Load(object sender, EventArgs e)
        {
            LoadSanPham();   
        }

        //Hien thi thong tin danh sach cac san pham
        public void LoadSanPham()
        {
            SanPhamBUS spBUS = new SanPhamBUS();
            DataTable dt = spBUS.LoadDanhSachSanPham();
            gvDSSanPham.DataSource = dt;
            gvDSSanPham.DataBind();
        }

        //load lai trang khi qua trang khac
        protected void gvDSSanPham_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            LoadSanPham();
            gvDSSanPham.PageIndex = e.NewPageIndex;
            gvDSSanPham.DataBind();
        }

        private bool CheckFileType(string FileName)
        {
            string ext = System.IO.Path.GetExtension(FileName);
            if (ext.Equals(".png") || ext.Equals(".jpg") || ext.Equals(".gif"))
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        protected void gvDSSanPham_RowEditing(object sender, GridViewEditEventArgs e)
        {
            int maSP = int.Parse(((Label)gvDSSanPham.Rows[e.NewEditIndex].FindControl("lbMaSP")).Text);
            Response.Redirect("CapNhatSanPham.aspx?id=" + maSP);
        }
    }
}